import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:wallpaper_app/components/AlertDialog/BlinkingPlaceholder.dart';
import 'package:wallpaper_app/tools/custom_image_cache.dart';

class ImageLoad extends StatelessWidget {
  final String imageUrl;
  final BoxFit fit;
  final double size;
  const ImageLoad({
    super.key,
    required this.imageUrl,
    this.fit = BoxFit.cover,
    this.size = 50,
  });

  @override
  Widget build(BuildContext context) {
    // 确保缓存目录存在
    CustomCacheManager.ensureCacheDirExists();
    final theme = Theme.of(context).colorScheme;
    return CachedNetworkImage(
      imageUrl: imageUrl,
      fit: BoxFit.cover,
      cacheManager: CustomCacheManager(),
      placeholder: (context, url) => Center(
        child: BlinkingPlaceholder(
          color: theme.onSurface.withOpacity(0.15),
        ),
      ),
      errorWidget: (context, url, error) => Icon(Icons.error),
    );
  }
}
